package org.itboys.rpc.admin;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.servlet.MultipartConfigElement;
import java.util.HashSet;
import java.util.Set;

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class AdminApplication extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {
        // -Dserver.port=$PORT 指定启动的 端口 右键 Run as 或 Debug as 的 Run Configuration
        // 或 Debug Configuration 的Arguments 的 vm arguments可修改启动端口
        // 可以这样加上 java -Dserver.port=8083 -Xms128m -Xmx128m -XX:PermSize=64m -Xss256k -XX:+DisableExplicitGC -XX:+UseParNewGC -XX:+UseCMSCompactAtFullCollection -XX:-CMSParallelRemarkEnabled -XX:+PrintGCTimeStamps -XX:+PrintGCDetails
        SpringApplication app = new SpringApplication(AdminApplication.class);
        app.setWebEnvironment(true);
        app.setShowBanner(false);
        Set<Object> set = new HashSet<Object>();
        set.add("applicationContext.xml");
        app.setSources(set);
        app.run(args);
    }

    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setMaxFileSize("1024KB");
        factory.setMaxRequestSize("1024KB");
        return factory.createMultipartConfig();
    }

    @Bean
    CommonsMultipartResolver multipartResolver(){
        return new CommonsMultipartResolver();
    }

}
